package com.zhdl.modules.demo.DCHTProcess;

import com.zhdl.hardware_contact.hardware_config.entity.ProjectConfiguration;
import com.zhdl.modules.process.common.GetPLCValue;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class MotorInterface implements GetPLCValue {


    List<ProjectConfiguration> configurationPLcList;
    public void initDate(){
        configurationPLcList = new ArrayList<>();
//        configurationPLcList.add(new ProjectConfiguration("MoveAbs_Pos[0]","0",1));
//        configurationPLcList.add(new ProjectConfiguration("MoveAbs_Done[0]","0",1));
//        configurationPLcList.add(new ProjectConfiguration("MoveAbs_Pos[1]","0",1));
//        configurationPLcList.add(new ProjectConfiguration("MoveAbs_Done[1]","0",1));
//        configurationPLcList.add(new ProjectConfiguration("MoveAbs_Pos[2]","0",1));
//        configurationPLcList.add(new ProjectConfiguration("MoveAbs_Done[2]","0",1));
//        configurationPLcList.add(new ProjectConfiguration("1#料仓夹紧气缸开到位","0",1));
//        configurationPLcList.add(new ProjectConfiguration("2#料仓夹紧气缸开到位","0",1));
//        configurationPLcList.add(new ProjectConfiguration("1#料仓夹紧气缸关到位","0",1));
//        configurationPLcList.add(new ProjectConfiguration("2#料仓夹紧气缸关到位","0",1));
//        configurationPLcList.add(new ProjectConfiguration("旋转夹紧位横移轴_MoveAbs_Pos[1]","0",1));
//        configurationPLcList.add(new ProjectConfiguration("打螺丝位横移轴_MoveAbs_Pos[1]","0",1));
//        configurationPLcList.add(new ProjectConfiguration("旋转夹紧位横移轴_MoveAbs_Pos[1]","0",1));
//        configurationPLcList.add(new ProjectConfiguration("CurrentPos","0",1));

    }

    @Override
    public ProjectConfiguration getValue(String field) {
        for (ProjectConfiguration configurationPLc : configurationPLcList) {
            if (configurationPLc.getField().equals(field)){
                return configurationPLc;
            }
        }
        return null;
    }

    public void setConfigurationPLcList(List<ProjectConfiguration> configurationPLcList){
        for (ProjectConfiguration projectConfiguration : this.configurationPLcList) {
            for (ProjectConfiguration configuration : configurationPLcList) {
                if(configuration.getField().equals(projectConfiguration.getField())){
                    projectConfiguration.setValue(configuration.getValue());
                    break;
                }
            }
        }
    }
}
